package com.zqweb.gulimall.member.web;

import com.alibaba.fastjson.JSON;
import com.zqweb.common.utils.R;
import com.zqweb.gulimall.member.feign.OrderFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.HashMap;
import java.util.Map;

@Controller
public class MemberWebController {
    @Autowired
    private OrderFeignService orderFeignService;

    @GetMapping("/memberOrder.html")
    // 支付成功后跳转到的商户订单列表页面
    public String memberOrderPage(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,Model model){
        // 根据分页查询参数调用远程的Order服务获取到当前登陆用户所关联的所有订单/订单项记录，然后携带上再来跳转
        Map<String, Object> params = new HashMap<>();
        params.put("page",pageNum.toString());// 当前页码
        R r = orderFeignService.getOrdersByMemberIdWithParams(params);
        model.addAttribute("orders",r);
//        System.out.println(JSON.toJSONString(r));
        return "orderList";
    }

}
